' Humans CR Validation Script
' 7/9/08 11:17 am

Option Strict Off
imports System
imports Humans=PHSRAG.Insight21.Humans
imports PHSRAG.Insight21.BusinessObjects
imports FormsManagement = PHSRAG.Insight21.FormsManagement
imports System.Collections
imports System.Web.UI
imports Utility=PHSRAG.Utility

module Script
	sub Main()
    
		' Pages for rediction
		const AttachmentsPageRedirection = -1

		'verify if all the ProtocolDocument records are either marked as hardcopy or there is an attachment tied to it
		For Each pD As Humans.ProtocolDocument In intrinsicProtocolProcess.ProtocolDocuments
			If not (pD.IsHardCopy or pD.DocumentId >0) Then
				LogMissingItem(AttachmentsPageRedirection, AttachmentsPageRedirection, _
						"Attachments", string.empty, string.empty, string.empty, "Attachment missing for " + pD.Name)
			End if  
		Next
			
    End Sub
    
    private function LogMissingItem(byval questionnaireVersionId as integer, byval questionnaireAnswerId as integer, byval logType as string, byval category as string, byval questionName as string, byval answer as string, byval description as string)
		Dim logItem As New Humans.LogItem(intrinsicCachePolicy)
		logItem.QuestionnaireVersionId = questionnaireVersionId
		logItem.QuestionnaireAnswerId = questionnaireAnswerId
		logItem.Type = logType
		logItem.QuestionName = questionName
		logItem.Category = category
		logItem.Answer = answer
		logItem.Description = description
		logItem.Completed =False
		SaveLogItem(logItem)
	end function

	'Save LogItem
	Sub SaveLogItem(ByVal logItem As Humans.LogItem)
		intrinsicProtocolProcess.SaveLogItem(logItem)
    End Sub
									
end module